package com.bj.dz.service.impl;


import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import com.bj.dz.mapper.UserMapper;
import org.springframework.stereotype.Service;

import com.bj.dz.entity.User;

@Service("userService")
public class UserServiceImp implements com.bj.dz.service.UserService {
    @Resource
    private UserMapper ud;

    public void setUd(UserMapper ud) {
        this.ud = ud;
    }


    /**
     * ��ѯ�Ƿ�����û���������
     */
    @Override
    public User findLoginUser(String userName, String pwd) {
        User user = ud.findLoginUser(userName, pwd);
        return user;
    }

    /**
     * ��ѯ�����û�
     */
    @Override
    public List<User> findUsers() {
        List<User> userList = ud.findUsers();
        if (userList == null) {
            userList = new ArrayList<User>();
        }
        return userList;
    }

    /**
     * ����û�
     */
    @Override
    public boolean saveUser(User user) {
        int num = ud.saveUser(user);
        boolean flag = (num > 0 ? true : false);
        return flag;
    }

    /**
     * �����ɫ
     */
    @Override
    public boolean assignRole(User user) {
        int num = ud.assignRole(user);
        boolean flag = (num > 0 ? true : false);
        return flag;
    }

    /**
     * ͨ����ɫid��ѯ�û�
     */
    @Override
    public List<User> findUserByRid(Integer rid) {
        List<User> userList = ud.findUserByRid(rid);
        if (userList == null) {
            userList = new ArrayList<User>();
        }
        return userList;
    }

    /**
     * ��������
     */
    @Override
    public boolean resetPwd(Integer id, String defaultPwd) {
        int num = ud.resetPwd(id, defaultPwd);
        boolean flag = (num > 0 ? true : false);
        return flag;
    }


}
